package dao;

import mapper.DeptMapper;
import mapper.UserMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import pojo.Dept;
import pojo.User;

import java.util.List;

@Repository
public class DeptDaoImpl implements DeptDao {
    private JdbcTemplate jdbcTemplate;
    @Override
    public int addDept(Dept dept) {


        String sql="insert into dept(deptid,deptname,number) values(null,?,?)";
        jdbcTemplate.update(sql,dept.getNumber(),dept.getDeptName());
        System.out.println("新增一个部门："+dept);
        return 114;

    }

    @Override
    public void update(Dept dept) {
        String sql="update dept SET deptname=?,number=? WHERE id=?";
        jdbcTemplate.update(sql,dept.getDeptName(),dept.getNumber(),dept.getDeptId());
        System.out.println("修改一个部门");
    }

    @Override
    public void delete(int deptid) {
        String sql="DELETE FROM dept WHERE deptname=?";
        jdbcTemplate.update(sql,deptid);
        System.out.println(deptid + "已删除");
    }

    @Override
    public List<Dept> findUserAll() {
        String sql="select * from dept";
        RowMapper<Dept> rowMapper=new DeptMapper();
        List<Dept> list=jdbcTemplate.query(sql,rowMapper);
        return list;
    }

    @Override
    public Dept findUserByNumber(int number) {
        String sql="select * from dept where deptid";
        RowMapper<Dept> rowMapper=new DeptMapper();
        Dept dept=jdbcTemplate.queryForObject(sql,rowMapper,number);
        return dept;

    }


}
